//
//  LZHomePresenter.m
//  laziz_Merchant
//
//  Created by xbnzd on 17/3/17.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZHomePresenter.h"

#import "GVUserDefaults+LZProperties.h"

#import "LZNewPromotionVC.h"
#import "LZScanQRCodeViewController.h"
#import "LZStaffAccountListViewController.h"
#import "LZCouponManagerListViewController.h"
#import "LZCouponManagerListViewController.h"
#import "LZManageReviewsViewController.h"
#import "LZManagePicturesViewController.h"
#import "LZOrderListViewController.h"
#import "LZFinancialSummaryViewController.h"
#import "LZMyCenterViewController.h"
#import "LZMyCollectionView.h"
#import "LZRestaurantAuthenticationViewController.h"
#import "LZAlertView.h"

@implementation LZHomePresenter

#pragma mark - 根据用户类型配置显示模块的图片
- (BOOL)configureDataSourceAndIsHiddenMsgBtnByUserTypeWithCollectionView:(LZMyCollectionView *)collectionView
{
    if ([[GVUserDefaults standardUserDefaults].userType integerValue] == kUserType_staff) {
        if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_all) {//员工权限都有
            collectionView.titleArray = @[LZLocalizedString(@"home_menu_new_promotion", nil),
                                          LZLocalizedString(@"home_menu_customer_checkout", nil),
                                          LZLocalizedString(@"home_menu_manage_coupons", nil),
                                          LZLocalizedString(@"home_menu_my_account", nil)];
            
            collectionView.iconArray = @[@[@"lz_home_new_promotion_hd",@"lz_home_new_promotion"],
                                         @[@"lz_home_customer_checkout_hd",@"lz_home_customer_checkout"],
                                         @[@"lz_home_manage_coupons_hd",@"lz_home_manage_coupons"],
                                         @[@"lz_home_my_account_hd",@"lz_home_my_account"]];
            
        }else if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_promotion){//只有发优惠的权限
            collectionView.titleArray = @[LZLocalizedString(@"home_menu_new_promotion", nil),
                                          LZLocalizedString(@"home_menu_manage_coupons", nil),
                                          LZLocalizedString(@"home_menu_my_account", nil)];
            
            collectionView.iconArray = @[@[@"lz_home_new_promotion_hd",@"lz_home_new_promotion"],
                                         @[@"lz_home_manage_coupons_hd",@"lz_home_manage_coupons"],
                                         @[@"lz_home_my_account_hd",@"lz_home_my_account"]];
            
        }else if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_checkout){//只有结账权限
            collectionView.titleArray = @[LZLocalizedString(@"home_menu_customer_checkout", nil),
                                          LZLocalizedString(@"home_menu_my_account", nil)];
            
            collectionView.iconArray = @[@[@"lz_home_customer_checkout_hd",@"lz_home_customer_checkout"],
                                         @[@"lz_home_my_account_hd",@"lz_home_my_account"]];
        }
        
        return YES;

    }else{
        collectionView.titleArray = @[LZLocalizedString(@"home_menu_new_promotion", nil),
                                      LZLocalizedString(@"home_menu_customer_checkout", nil),
                                      LZLocalizedString(@"home_menu_manage_staff", nil),
                                      LZLocalizedString(@"home_menu_manage_coupons", nil),
                                      LZLocalizedString(@"home_menu_manage_reviews", nil),
                                      LZLocalizedString(@"home_menu_manage_pictures", nil),
                                      LZLocalizedString(@"home_menu_manage_orders", nil),
                                      LZLocalizedString(@"home_menu_financial_records", nil),
                                      LZLocalizedString(@"home_menu_my_account", nil)];
        
        collectionView.iconArray = @[@[@"lz_home_new_promotion_hd",@"lz_home_new_promotion"],
                                     @[@"lz_home_customer_checkout_hd",@"lz_home_customer_checkout"],
                                     @[@"lz_home_manage_staff_hd",@"lz_home_manage_staff"],
                                     @[@"lz_home_manage_coupons_hd",@"lz_home_manage_coupons"],
                                     @[@"lz_home_manage_reviews_hd",@"lz_home_manage_reviews"],
                                     @[@"lz_home_manage_pictures_hd",@"lz_home_manage_pictures"],
                                     @[@"lz_home_manage_orders_hd",@"lz_home_manage_orders"],
                                     @[@"lz_home_financial_records_hd",@"lz_home_financial_records"],
                                     @[@"lz_home_my_account_hd",@"lz_home_my_account"]];
        
        return NO;
    }
    
    return YES;
    
}


#pragma mark - vc 根据权限跳转
- (void)pushToVCBaseIndexPath:(NSIndexPath *)indexPath FromVC:(UIViewController *)viewcontroller
{
    if ([[GVUserDefaults standardUserDefaults].userType integerValue] == kUserType_staff){
        
        if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_all) {
            
            [self loadItemClickForStaffAllRoleWithIndex:indexPath FromVC:viewcontroller];
            
        }else if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_promotion){
        
            [self loadItemClickForStaffPromotionRoleWithIndex:indexPath FromVC:viewcontroller];
            
        }else if ([[GVUserDefaults standardUserDefaults].staffRole integerValue] == kStaffType_checkout){
        
            [self loadItemClickForStaffCheckoutRoleWithIndex:indexPath FromVC:viewcontroller];
        }
    }else{
        
        [self loadItemClickForManagerWithIndex:indexPath FromVC:viewcontroller];
    }
}


/**
 管理端各项跳转

 @param indexP <#indexP description#>
 @param viewcontroller <#viewcontroller description#>
 */
- (void)loadItemClickForManagerWithIndex:(NSIndexPath *)indexP FromVC:(UIViewController *)viewcontroller
{
    if ([GVUserDefaults standardUserDefaults].authType == kAuthType_noneAuth && indexP.row != 8) {
        LZRestaurantAuthenticationViewController* vc = [[LZRestaurantAuthenticationViewController alloc] init];
        [viewcontroller.navigationController pushViewController:vc animated:YES];
        return;
    }else if ([GVUserDefaults standardUserDefaults].authType == kAuthType_waitAuth && indexP.row != 8){
        LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"res_auth_wait", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
        [alert show];
        return;
    }else if ([GVUserDefaults standardUserDefaults].authType == kAuthType_rejectAuth && indexP.row != 8){
        LZRestaurantAuthenticationViewController* vc = [[LZRestaurantAuthenticationViewController alloc] init];
        vc.regected = YES;
        [viewcontroller.navigationController pushViewController:vc animated:YES];
        
        return;

    }

    switch (indexP.row) {
        case 0: //发优惠
        {
            //zhoubo fix 2017.04.14
            LZNewPromotionVC * vc = [[LZNewPromotionVC alloc] initWithNibName:@"LZNewPromotionVC" bundle:nil];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1: //结账
        {
            LZScanQRCodeViewController *vc = [[LZScanQRCodeViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2: //员工管理
        {
            LZStaffAccountListViewController *vc = [[LZStaffAccountListViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3: //优惠管理
        {
            LZCouponManagerListViewController *vc = [[LZCouponManagerListViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4: //评价管理
        {
            LZManageReviewsViewController *vc = [[LZManageReviewsViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 5: //照片管理
        {
            
            LZManagePicturesViewController *vc = [[LZManagePicturesViewController alloc] initWithNibName:@"LZManagePicturesViewController" bundle:nil];
            
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 6: //订单管理
        {
            LZOrderListViewController *vc = [[LZOrderListViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 7: //财务结款
        {
            LZFinancialSummaryViewController *vc = [[LZFinancialSummaryViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 8: //个人中心
        {
            LZMyCenterViewController * vc = [[LZMyCenterViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        default:
            break;
    }

}


/**
 员工登陆跳转, 全 权限

 @param indexP <#indexP description#>
 @param viewcontroller <#viewcontroller description#>
 */
- (void)loadItemClickForStaffAllRoleWithIndex:(NSIndexPath *)indexP FromVC:(UIViewController *)viewcontroller
{
    switch (indexP.row) {
        case 0: //发优惠
        {
            LZNewPromotionVC * vc = [[LZNewPromotionVC alloc] initWithNibName:@"LZNewPromotionVC" bundle:nil];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1: //结账
        {
            LZScanQRCodeViewController *vc = [[LZScanQRCodeViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2: //优惠管理
        {
            LZCouponManagerListViewController *vc = [[LZCouponManagerListViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3: //个人中心
        {
            LZMyCenterViewController * vc = [[LZMyCenterViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        default:
            break;
    }

}


/**
 员工跳转 只有优惠权限

 @param indexP <#indexP description#>
 @param viewcontroller <#viewcontroller description#>
 */
- (void)loadItemClickForStaffPromotionRoleWithIndex:(NSIndexPath *)indexP FromVC:(UIViewController *)viewcontroller
{
    switch (indexP.row) {
        case 0: //发优惠
        {
            LZNewPromotionVC * vc = [[LZNewPromotionVC alloc] initWithNibName:@"LZNewPromotionVC" bundle:nil];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1: //优惠管理
        {
            LZCouponManagerListViewController *vc = [[LZCouponManagerListViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2: //个人中心
        {
            LZMyCenterViewController * vc = [[LZMyCenterViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        default:
            break;
    }

}


/**
 员工跳转 只有结账权限

 @param indexP <#indexP description#>
 @param viewcontroller <#viewcontroller description#>
 */
- (void)loadItemClickForStaffCheckoutRoleWithIndex:(NSIndexPath *)indexP FromVC:(UIViewController *)viewcontroller
{
    switch (indexP.row) {
        case 0: //结账
        {
            LZScanQRCodeViewController *vc = [[LZScanQRCodeViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1: //个人中心
        {
            LZMyCenterViewController * vc = [[LZMyCenterViewController alloc] init];
            [viewcontroller.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        default:
            break;
    }

}

@end
